package ooday03;

public class RefArrayDemo {
    public static void main(String[] args) {
        Dog[] dogs = new Dog[3];
        dogs[0]  = new Dog("小黑",3,"灰");
        dogs[1]  = new Dog("小白",3,"黑");
        dogs[2]  = new Dog("小灰",3,"白");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;
        dogs[2].swim();
        for (int i=0;i<dogs.length;i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小黄",3,"黄");
        chicks[1] = new Chick("大黄",3,"黄");
        for (int i=0;i<chicks.length;i++){
            System.out.println(chicks[i].name);
            chicks[i].layEggs();
        }


        Fish[] fish = new Fish[4];
        fish[0] = new ooday03.Fish("小金",2,"金");
        fish[1] = new ooday03.Fish("大金",4,"金");
        fish[2] = new ooday03.Fish("小绿",1,"绿");
        fish[3] = new ooday03.Fish("小红",3,"红");
        for (int i=0;i<fish.length;i++){
            System.out.println(fish[i].color);
            fish[i].swim();
        }







        /*
        Dog[] dogs = new Dog[3];
        dogs[0]  = new Dog("小黑",3,"灰");
        dogs[1]  = new Dog("小白",3,"黑");
        dogs[2]  = new Dog("小灰",3,"白");
        System.out.println(dogs[0].name);

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小黄",3,"黄");
        chicks[1] = new Chick("大黄",3,"黄");

         */

        //默认值为null
        /*
        Dog[] dog1 = new Dog[3];
        dog1[0]  = new Dog("小黑",3,"黑色")
        Chick[] chick = new Chick[3];

        Fish[] fish = new Fish[2];

         */

    }
}
